package com.ruoyi.system.service.impl;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.jlx.distribution.api.Distribution;
import com.jlx.distribution.pojo.endorse.*;
import com.jlx.distribution.pojo.order.CreateOrderRequest;
import com.jlx.distribution.pojo.order.CreateOrderResponse;
import com.jlx.distribution.pojo.order.OrderDetail;
import com.jlx.distribution.pojo.order.QueryOrderRequest;
import com.jlx.distribution.pojo.payapply.input.PayApplyParam;
import com.jlx.distribution.pojo.payapply.output.PayApplyResult;
import com.jlx.distribution.pojo.payok.input.PayOkParam;
import com.jlx.distribution.pojo.payok.output.PayOkResult;
import com.jlx.distribution.pojo.payvalid.input.PayValidParam;
import com.jlx.distribution.pojo.payvalid.output.PayValidResult;
import com.jlx.distribution.pojo.postexpress.PostExpressRequest;
import com.jlx.distribution.pojo.postexpress.PostExpressResponse;
import com.jlx.distribution.pojo.refund.apply.ApplyRefundTicketRequest;
import com.jlx.distribution.pojo.refund.apply.ApplyRefundTicketResponse;
import com.jlx.distribution.pojo.refund.confirm.ConfirmRefundTicketRequest;
import com.jlx.distribution.pojo.refund.confirm.ConfirmRefundTicketResponse;
import com.jlx.distribution.pojo.refund.detail.QueryRefundTicketDetailRequest;
import com.jlx.distribution.pojo.refund.detail.QueryRefundTicketDetailResponse;
import com.jlx.distribution.pojo.refund.fee.QueryRefundTicketFeeRequest;
import com.jlx.distribution.pojo.refund.fee.QueryRefundTicketFeeResponse;
import com.jlx.distribution.pojo.refund.mistake.MistakeRefundRequest;
import com.jlx.distribution.pojo.refund.mistake.MistakeRefundResponse;
import com.jlx.distribution.pojo.search.input.SearchParam;
import com.jlx.distribution.pojo.search.output.SearchResult;
import com.jlx.distribution.pojo.ticket.input.TicketParam;
import com.jlx.distribution.pojo.ticketcheck.input.TicketCheckRequest;
import com.jlx.distribution.pojo.ticketcheck.output.TicketCheckResponse;
import com.jlx.distribution.pojo.verify.input.VerifyParam;
import com.jlx.distribution.pojo.verify.output.VerifyResult;
import com.ruoyi.common.utils.RequestContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class DistributionServiceImpl implements Distribution {

    private static final Logger logger = LoggerFactory.getLogger(DistributionServiceImpl.class);

    @Override
    public SearchResult search(SearchParam searchParam) {
        try{
            logger.debug("jlx search param : {}",JSONObject.toJSONString(searchParam));
            String response= HttpUtil.post("https://openapi.jiulvxing.com/distribute/search", JSONObject.toJSONString(searchParam));
            logger.debug("jlx search response : {}",response);
            return JSONObject.parseObject(response,SearchResult.class);
        }catch (Exception e){
            logger.error("jlx search error",e);
        }
        return null;
    }

    @Override
    public VerifyResult verify(VerifyParam verifyParam) {
       // for(int i=0;i<2;i++){
            try{
                logger.info("jlx booking param : {}",JSONObject.toJSONString(verifyParam));
                String response= HttpUtil.post("https://openapi.jiulvxing.com/distribute/booking", JSONObject.toJSONString(verifyParam));
                logger.info("jlx booking response : {}",response);
                return JSONObject.parseObject(response,VerifyResult.class);
            }catch (Exception e){
                logger.error("jlx booking error",e);
            }
           // verifyParam.setContext(RequestContextUtil.buildDefaultContext());
        //}
        return null;
    }

    @Override
    public CreateOrderResponse order(CreateOrderRequest createOrderRequest) {
        try{
            logger.info("jlx order param : {}",JSONObject.toJSONString(createOrderRequest));
            String response= HttpUtil.post("https://openapi.jiulvxing.com/distribute/order", JSONObject.toJSONString(createOrderRequest));
            logger.info("jlx order response : {}",response);
            return JSONObject.parseObject(response,CreateOrderResponse.class);
        }catch (Exception e){
            logger.error("jlx order error",e);
        }
        return null;
    }

    @Override
    public PostExpressResponse postExpress(PostExpressRequest postExpressRequest) {
        return null;
    }

    @Override
    public PayValidResult payValid(PayValidParam payValidParam) {
        try{
            logger.info("jlx payValid param : {}",JSONObject.toJSONString(payValidParam));
            String response= HttpUtil.post("https://openapi.jiulvxing.com/distribute/payValid", JSONObject.toJSONString(payValidParam));
            logger.info("jlx payValid response : {}",response);
            return JSONObject.parseObject(response,PayValidResult.class);
        }catch (Exception e){
            logger.error("jlx payValid error",e);
        }
        return null;
    }

    @Override
    public PayApplyResult payApply(PayApplyParam payApplyParam) {
        return null;
    }

    @Override
    public PayOkResult payOk(PayOkParam payOkParam) {
        try{
            logger.info("jlx payNotify param : {}",JSONObject.toJSONString(payOkParam));
            String response= HttpUtil.post("https://openapi.jiulvxing.com/distribute/payNotify", JSONObject.toJSONString(payOkParam));
            logger.info("jlx payNotify response : {}",response);
            return JSONObject.parseObject(response,PayOkResult.class);
        }catch (Exception e){
            logger.error("jlx payNotify error",e);
        }
        return null;
    }

    @Override
    public OrderDetail orderDetail(QueryOrderRequest queryOrderRequest) {
        try{
            logger.info("jlx orderDetail param : {}",JSONObject.toJSONString(queryOrderRequest));
            String response= HttpUtil.post("https://openapi.jiulvxing.com/distribute/orderDetail", JSONObject.toJSONString(queryOrderRequest));
            logger.info("jlx orderDetail response : {}",response);
            return JSONObject.parseObject(response,OrderDetail.class);
        }catch (Exception e){
            logger.error("jlx payNotify error",e);
        }
        return null;
    }

    @Override
    public ApplyRefundTicketResponse applyRefund(ApplyRefundTicketRequest applyRefundTicketRequest) {
        return null;
    }

    @Override
    public QueryRefundTicketFeeResponse queryRefundFee(QueryRefundTicketFeeRequest queryRefundTicketFeeRequest) {
        try{
            logger.info("jlx queryRefundFee param : {}",JSONObject.toJSONString(queryRefundTicketFeeRequest));
            String response= HttpUtil.post("https://openapi.jiulvxing.com/distribute/queryRefundFee", JSONObject.toJSONString(queryRefundTicketFeeRequest));
            logger.info("jlx queryRefundFee response : {}",response);
            return JSONObject.parseObject(response,QueryRefundTicketFeeResponse.class);
        }catch (Exception e){
            logger.error("jlx queryRefundFee error",e);
        }
        return null;
    }

    @Override
    public ConfirmRefundTicketResponse confirmRefund(ConfirmRefundTicketRequest confirmRefundTicketRequest) {
        try{
            logger.info("jlx confirmRefund param : {}",JSONObject.toJSONString(confirmRefundTicketRequest));
            String response= HttpUtil.post("https://openapi.jiulvxing.com/distribute/confirmRefund", JSONObject.toJSONString(confirmRefundTicketRequest));
            logger.info("jlx confirmRefund response : {}",response);
            return JSONObject.parseObject(response,ConfirmRefundTicketResponse.class);
        }catch (Exception e){
            logger.error("jlx confirmRefund error",e);
        }
        return null;
    }

    @Override
    public void confirmRefundAsyn(ConfirmRefundTicketRequest confirmRefundTicketRequest) {

    }

    @Override
    public QueryRefundTicketDetailResponse queryRefundDetail(QueryRefundTicketDetailRequest queryRefundTicketDetailRequest) {
        return null;
    }

    @Override
    public ApplyChgDetail applyChangeDetail(ApplyChgReq applyChgReq) {
        return null;
    }

    @Override
    public ChgFlightSearchRes searchChgFlight(ChgFlightSearchReq chgFlightSearchReq) {
        try{
            logger.info("jlx searchChangeFlight param : {}",JSONObject.toJSONString(chgFlightSearchReq));
            String response= HttpUtil.post("https://openapi.jiulvxing.com/distribute/searchChangeFlight", JSONObject.toJSONString(chgFlightSearchReq));
            logger.info("jlx searchChangeFlight response : {}",response);
            return JSONObject.parseObject(response,ChgFlightSearchRes.class);
        }catch (Exception e){
            logger.error("jlx searchChangeFlight error",e);
        }
        return null;
    }

    @Override
    public ChgCreateOrderRes createChangeOrder(ChgCreateOrderReq chgCreateOrderReq) {
        try{
            logger.info("jlx createChangeOrder param : {}",JSONObject.toJSONString(chgCreateOrderReq));
            String response= HttpUtil.post("https://openapi.jiulvxing.com/distribute/createChangeOrder", JSONObject.toJSONString(chgCreateOrderReq));
            logger.info("jlx createChangeOrder response : {}",response);
            return JSONObject.parseObject(response,ChgCreateOrderRes.class);
        }catch (Exception e){
            logger.error("jlx createChangeOrder error",e);
        }
        return null;
    }

    @Override
    public ChgDetailRes queryChangeDetail(ChgDetailReq chgDetailReq) {
        try{
            logger.info("jlx queryChangeDetail param : {}",JSONObject.toJSONString(chgDetailReq));
            String response= HttpUtil.post("https://openapi.jiulvxing.com/distribute/queryChangeDetail", JSONObject.toJSONString(chgDetailReq));
            logger.info("jlx queryChangeDetail response : {}",response);
            return JSONObject.parseObject(response,ChgDetailRes.class);
        }catch (Exception e){
            logger.error("jlx queryChangeDetail error",e);
        }
        return null;
    }

    @Override
    public TicketParam ticketOk(String s) {
        return null;
    }

    @Override
    public MistakeRefundResponse mistakeRefund(MistakeRefundRequest mistakeRefundRequest) {
        return null;
    }

    @Override
    public TicketCheckResponse ticketCheck(TicketCheckRequest ticketCheckRequest) {
        return null;
    }

    @Override
    public boolean filter(String s, String s1, String s2, String s3, int i, boolean b, SearchParam searchParam) {
        return false;
    }

    @Override
    public int getOutPutProductSize(SearchParam searchParam) {
        return 0;
    }
}
